package com.zeny.coding.dto;


import com.zeny.coding.util.DtoUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.xml.bind.ValidationException;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class FileDto {

    private String id;

    private String path;

    private String name;

    private String suffix;

    private Integer size;

    private String use;

    private Date createdAt;

    private Date updatedAt;

    /**
     * <h2>base64</h2>
     * @param null
     **/
    private String shard;

    /**
     * <h2>分片索引</h2>
     * @param null
     **/
    private Integer shardIndex;

    /**
     * <h2>分片大小</h2>
     * @param null
     **/
    private Integer shardSize;

    /**
     * <h2>总分片</h2>
     * @param null
     **/
    private Integer shardTotal;

    private String key;

    private String vod;

    public void valid() throws ValidationException {
        //检查文件名字
        DtoUtil.valid(this.name, true, 1, 100);
        //检查文件后缀
        DtoUtil.valid(this.suffix, true, 1, 100);
        //检查文件大小
        DtoUtil.require(this.size);
        //检查文件用途
        DtoUtil.valid(this.use, true, 1, 1);
        //检查文件分片索引
        DtoUtil.require(this.shardIndex);
        //检查文件分片大小
        DtoUtil.require(this.shardSize);
        //检查文件分片总数量
        DtoUtil.require(shardTotal);
        //检查文件标识
        DtoUtil.valid(this.key, true, 1, 32);
    }

    public void validForDelete() throws ValidationException {
        DtoUtil.valid(this.id, true, 1, 19);
        DtoUtil.valid(this.path, false, 1, 100);
        DtoUtil.valid(this.vod, false, 1, 32);
    }
}